# 1. 可以组成网络的服务器

1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let n, m;
let visited = [];
let server = [];
rl.on('line', (line) => {
    if (!n) {
        [n, m] = line.split(' ').map(Number);
        visited = new Array(n).fill(false).map(() => new Array(m).fill(false));
    } else {
        server.push(line.split(' ').map(Number));
        if (server.length === n) {
            let ans = 0;
            for(let i=0; i<n; i++) {
                for(let j=0; j<m; j++) {
                    ans = Math.max(ans, dfs(i, j));
                }
            }
            console.log(ans);
        }
    }
})

function dfs (i, j) {
    if (i<0 || i>=n || j<0 || j>=m || server[i][j] === 0) {
        return 0;
    }

    if (visited[i][j]) {
        return 0;
    }

    visited[i][j] = true;

    let count = 1;
    count += dfs(i-1, j);
    count += dfs(i+1, j);
    count += dfs(i, j-1);
    count += dfs(i, j+1);

    return count;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47